//
//  NextViewController.m
//  侧滑导致的App假死
//
//  Created by chenleping on 2019/3/12.
//  Copyright © 2019年 DSY. All rights reserved.
//

#import "NextViewController.h"

#import "BaseNavigationController.h"

#import "ThirdViewController.h"
@interface NextViewController ()

@property (nonatomic, assign) BOOL isCanSideBack;

@end

@implementation NextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor greenColor];
    
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:btn];
    btn.backgroundColor = [UIColor redColor];
    btn.frame = CGRectMake(0, 100, 100, 100);
    [btn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setTitle:@"<返回>" forState:UIControlStateNormal];
    backBtn.backgroundColor = [UIColor redColor];
    [backBtn addTarget:self action:@selector(clickBackBtn:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    NSLog(@"%@", NSStringFromSelector(_cmd));
    // 需要在viewDidAppear中禁用侧滑返回，否则会造成页面假死
    BaseNavigationController * baseNav = (BaseNavigationController *)self.navigationController;
    baseNav.interactivePopGestureRecognizerEnable = NO;
    baseNav.panGestureEnable = NO;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    BaseNavigationController * baseNav = (BaseNavigationController *)self.navigationController;
    baseNav.interactivePopGestureRecognizerEnable = YES;
    baseNav.panGestureEnable = YES;
}

- (void)clickBtn{
    ThirdViewController * thirdVC = [ThirdViewController new];
    [self.navigationController pushViewController:thirdVC animated:YES];
}

- (void)clickBackBtn:(UIButton *)btn {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
